//
//  WWButton.m
//  YiQiTingShu
//
//  Created by WeiWei on 15/11/6.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//

#import "WWButton.h"
#import "UIView+Extension.h"

@implementation WWButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
        [self setTitle:@"请收藏" forState:UIControlStateNormal];
        [self setTitle:@"已收藏" forState:UIControlStateSelected];
        [self setTitleColor:[ThemeManage shareThemeManage].textColor forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"shoucang.png"] forState:UIControlStateNormal];
        [self addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
         [self setImage:[UIImage imageNamed:@"shoucang2.png"] forState:UIControlStateSelected];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleLabel.y = self.imageView.y + self.imageView.height;
    self.titleLabel.x = self.imageView.x - 3;
}

- (void)buttonClicked {
    self.selected = !self.selected;
}

- (void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    
    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];

    [self sizeToFit];
}

@end
